#include <main.h>


uint pwm_high=500,pwm_dly,main_dly;
float pid_speed;
char chuang_tab[1];
void main_copy();


void main()
{
	UartInit();
	Timer0Init();
//	Timer1Init();
//	pid_init();
	while(1)
	{
		main_copy();
	}
}


void time0() interrupt 1
{
	if(++main_dly==200)main_dly=0;	
	if(++pwm_dly==1000)pwm_dly=0;
	
	if(pwm_dly<pwm_high){front_left_pwm=1;front_right_pwm=1;back_left_pwm=1;back_right_pwm=1;}
	else if(pwm_dly>pwm_high){front_left_pwm=0;front_right_pwm=0;back_left_pwm=0;back_right_pwm=0;}
		
//		if(++pwm_dly==pid_speed)pwm_dly=0;
//	
//		if(pwm_dly<pwm_high){front_left_pwm=0;front_right_pwm=0;back_left_pwm=0;back_right_pwm=0;}
//		else if(pwm_dly>pwm_high){front_left_pwm=1;front_right_pwm=1;back_left_pwm=1;back_right_pwm=1;}

}


void main_copy()
{
	if(main_dly) return;
	main_dly=1;
//	pid_speed=main_pid(200.0);
	main_waishe(chuang_tab[0]);
//	printf("pid_speed=%f\r\n",(uint)pwm_high);
//	pwm_high=(uint)main_pid(pid_speed);
//	if(RI){printf("pwm_high=%d\r\n",(uint)pwm_high);}
}

void time4() interrupt 4
{
	if(RI)
	{
		RI=0;
		chuang_tab[0]=SBUF;		
		printf("pwm_high=%d\r\n",(uint)pwm_high);
	}
}

void datko(char dat)
{
	SBUF=dat;
	while(!TI);
	TI=0;
}

char putchar(char c)
{
	datko(c);
	return c;
}